
@import 'tweaks-temp';

// Theme colors
$theme_blue:       #4285F4;
$theme_teal:       #2EB398;
$theme_red:        #F0544C;
$theme_purple:     #AB47BC;
$theme_green:      #86BE43;
$theme_grey:       #666666;
$theme_base:       if($variant == 'light', #FFFFFF, #333333);
$theme_background: if($variant == 'light', #F2F2F2, #282828);

// Base functions
@function gtkalpha($c,$a) {
  @return unquote("alpha(#{$c},#{$a})");
}

@function gtkmix($c1,$c2,$r) {
  $ratio: 1 -  $r / 100%; // match SCSS mix()
  @return unquote("mix(#{$c1},#{$c2},#{$ratio})");
}

@function gtkshade($c,$s) {
  @return unquote("shade(#{$c},#{$s})");
}

@function gtkcolor($c) {
  @return unquote("@#{$c}");
}

// Color functions
@function on($color, $state: 'primary') {
  // Allow 'light' or 'dark' to $theme
  @if ($color == 'light') { $color: white; }
  @if ($color == 'dark') { $color: black; }

  // Calculate color brightness according to https://www.w3.org/TR/AERT/#color_contrast
  $brightness: (red($color) * 299 + green($color) * 568 + blue($color) * 114) / 1000;

  @if ($brightness >= 156) {
    @if ($state == 'primary') { @return rgba(black, 0.87); }
    @if ($state == 'secondary') { @return rgba(black, 0.6); }
    @if ($state == 'disabled') { @return rgba(black, 0.38); }
    @if ($state == 'secondary-disabled') { @return rgba(black, 0.26); }
    @if ($state == 'track') { @return rgba(black, 0.26); }
    @if ($state == 'track-disabled') { @return rgba(black, 0.15); }
    @if ($state == 'divider') { @return rgba(black, 0.12); }
    @if ($state == 'fill') { @return rgba(black, 0.05); }
  } @else {
    @if ($state == 'primary') { @return white; }
    @if ($state == 'secondary') { @return rgba(white, 0.7); }
    @if ($state == 'disabled') { @return rgba(white, 0.45); }
    @if ($state == 'secondary-disabled') { @return rgba(white, 0.3); }
    @if ($state == 'track') { @return rgba(white, 0.3); }
    @if ($state == 'track-disabled') { @return rgba(white, 0.15); }
    @if ($state == 'divider') { @return rgba(white, 0.12); }
    @if ($state == 'fill') { @return rgba(white, 0.05); }
  }
}

@function primary($state: 'main') {
  @if ($state == 'main') {
    @if ($theme == 'doder')    { @return $theme_blue; }
    @if ($theme == 'beryl')    { @return $theme_teal; }
    @if ($theme == 'ruby')     { @return $theme_red; }
    @if ($theme == 'amethyst') { @return $theme_purple; }
    @if ($theme == 'jade')     { @return $theme_green; }
    @if ($theme == 'grey')     { @return $theme_grey; }
  }
  @if ($state == 'contrast') { // entry/slider (focus)
    @if ($variant == 'light')  { @return rgba(black, 0.65); }
    @if ($variant == 'dark')   { @return rgba(white, 1); }
  }
  @if ($state == 'default') { // for default mix grey color
    @if ($theme == 'doder') or ($theme == 'beryl') or ($theme == 'amethyst') { @return $theme_blue; }
    @else { @return $theme_grey; }
  }
}

@function accent($state: 'main') {
  @if ($state == 'main') {
    @if ($theme == 'doder')    { @return #18b8ff; }
    @if ($theme == 'beryl')    { @return #0fd1ab; }
    @if ($theme == 'ruby')     { @return #FF626C; }
    @if ($theme == 'amethyst') { @return #EC407A; }
    @if ($theme == 'jade')     { @return #72bb8d; }
    @if ($theme == 'grey')     { @return lighten($theme_grey, 8%); }
  }
  @if ($state == 'contrast') {
    @if ($variant == 'light')  { @return rgba(black, 0.58); }
    @if ($variant == 'dark')   { @return rgba(white, 0.86); }
  }
}

@function indicator($state: 'primary') {
  @if ($state == 'primary') {
    @if ($theme == 'grey') { @return primary(contrast); }
    @else { @return primary(main); }
  }
  @if ($state == 'accent') {
    @if ($theme == 'grey') { @return accent(contrast); }
    @else { @return accent(main); }
  }
  @if ($state == 'light') {
    @if ($theme == 'grey') { @return white; }
    @else { @return primary(main); }
  }
  @if ($state == 'header') {
    @if ($theme == 'grey') {
      @if ($topbar == 'light')  { @return rgba(black, 0.65); }
      @if ($topbar == 'dark')   { @return rgba(white, 1); }
    }
    @else { @return primary(main); }
  }
}

@function themecolor($color, $state: 'default') {
  @if ($state == 'main') {
    @return mix(primary(main), $color, $weight);
  }
  @if ($state == 'primary') {
    @if ($theme != 'grey') {
      @return mix(primary(main), $color, $weight);
    } @else { @return $color; }
  }
  @if ($state == 'default') { // for default mix grey color
    @if ($theme != 'grey') {
      @return mix(primary(default), $color, $weight);
    } @else { @return $color; }
  }
}

@function overlay($color, $state: 'normal') {
  @if ($state == 'normal') { @return rgba(on($color), 0.05); }
  @if ($state == 'hover') { @return rgba(on($color), 0.1); }
  @if ($state == 'focus') { @return rgba(on($color), 0.08); }
  @if ($state == 'active') { @return rgba(on($color), 0.16); }
  @if ($state == 'checked') { @return rgba(on($color), 0.13); }
  @if ($state == 'selected') { @return rgba(on($color), 0.1); }
}

@function highlight($color) {
  @if (lightness($color) >= 80%) { @return rgba($white, 0.15); }
  @else if (lightness($color) >= 40%) { @return rgba($white, 0.35); }
  @else { @return rgba($white, 0.1); }
}
